import axios from "axios";
import { message as antdMessage } from "antd";

export const request = axios.create({
  timeout: 10000,
  timeoutErrorMessage: "链接超时....",
});

// 响应拦截
request.interceptors.response.use(
  (resp) => {
    const { code, message } = resp.data;

    switch (code) {
      case 200:
        antdMessage.success(message);
        break;
      case 400:
        antdMessage.error(message);
        break;
    }

    return resp;
  },
  (error) => {
    return Promise.reject(error);
  }
);
